#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>

void main(int argc,char *argv[])
{
    FILE *fp1 = fopen("1.txt","w+");
    FILE *fp2 = fopen("2.txt","w+");

    char data[1024];
    
    while(fgets(data,sizeof(data),stdin) != NULL)
    {
        if (strcmp(data, "#\n") == 0)
        {
            break;
        }
        fseek(fp1 , 0 , SEEK_SET);
        fflush(fp1);
        int f1 = fputs(data,fp1);
        if(f1 == EOF)
        {
            perror("fputs failed1");
            fclose(fp1);

            return ;
        }
        
        if(fgets(data,sizeof(data),fp1))
        {
            perror("fgets failed2");
            fclose(fp1);
            fclose(fp2);

            return ;
        }
        fseek(fp2, 0, SEEK_SET);
        /* 写数据到tar_2.txt */
        int f2 = fputs(data, fp2); 
        if(f2 == EOF)
        {
            perror("fputs failed3");
            fclose(fp1);
            fclose(fp2);

            return ;
        }
    }
    

    fclose(fp1);
    fclose(fp2);
}